package com.crm.system.controller.customerManager;

import com.alibaba.fastjson.JSONObject;
import com.crm.common.model.DataResponse;
import com.crm.common.model.DhPageInfo;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.model.vo.customerManager.NewSingleMemberStatisticsVO;
import com.crm.system.service.customerManager.NewMemberAnalyseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 新会员分析
 *
 * @author luojie
 * @date 2021/5/25 10:31
 */
@RestController
@RequestMapping("/newMemberAnalyse")
@Slf4j
public class NewMemberAnalyseController {

    @Autowired
    private NewMemberAnalyseService newMemberAnalyseService;

    /***
     * @Description:通过上年度/本年度范围来获取12个月统计
     * @Param: dateUnit 上年度传0/本年度传1
     * @Author: luojie
     * @Date: 2021/5/25 10:44
     */
    @GetMapping("/getNewMemberMonthlyStatistics")
    public DataResponse getNewMemberMonthlyStatistics(@RequestParam("startDate") String startDate, @RequestParam("endDate") String endDate) {
//        List<JSONObject> result =  newMemberAnalyseService.getNewMemberMonthlyStatistics(dateUnit);
        List<JSONObject> result = newMemberAnalyseService.getEveryMonthlyNewMemberStatistics(startDate, endDate);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), result);
    }

    /**
     * 本月新单会员统计
     *
     * @param pageIndex
     * @param pageSize
     * @return
     */
    @GetMapping("/getNewSingleMemberStatistics")
    public DataResponse getNewSingleMemberStatistics(@RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                                     @RequestParam(value = "pageSize", required = true) Integer pageSize,
                                                     @RequestParam(value = "yearMonth", required = true) String yearMonth,
                                                     @RequestParam(value = "contractType", required = true) String contractType
    ) {
        // 添加月份字段、添加会员新、续费会员字段
//        DhPageInfo<NewSingleMemberStatisticsVO> result = newMemberAnalyseService.getNewSingleMemberStatistics(pageIndex, pageSize);
        DhPageInfo<NewSingleMemberStatisticsVO> result = newMemberAnalyseService.selectNewSingleMemberStatisticsByContract(pageIndex, pageSize, yearMonth, contractType);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), result);
    }

    /***
     * @Description:获得本月新增会员、续费会员、非会员额度
     * @Author: luojie
     * @Date: 2021/5/26 15:41
     */
    @GetMapping("/getPercentageQuotaStatistics")
    public DataResponse getPercentageQuotaStatistics() {
        JSONObject result = newMemberAnalyseService.getPercentageQuotaStatistics();
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), result);
    }

}
